<table border="2px">
<tr>
<th>Best players</th>
<th>wins</th>
<th>looses</th>
</tr>
<?php
mysql_connect('localhost', 'root');
mysql_select_db('dots');

$query = "SELECT users.userID AS uID, login ,
(SELECT COUNT(*) FROM battles WHERE( (autorID = uID AND turn = 0) OR (guestID = uID AND turn = 1)) AND finish = 1) AS wins, 
(SELECT COUNT(*) FROM battles WHERE ((autorID = uID AND turn = 1) OR (guestID = uID AND turn = 0)) AND finish = 1) AS looses 
FROM users ORDER BY wins DESC LIMIT 0, 5;";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

while ($row)
{
	print '<tr>';
	print '<td>'.$row[1].'</td>';
	print '<td>'.$row[2].'</td>';
	print '<td>'.$row[3].'</td>';
	print '</tr>';
	$row = mysql_fetch_array($result);
}
?>
</table>
